﻿using System;
using System.Text.RegularExpressions;
using Wedn.Core.Service;
using Wedn.Core.Utility;


namespace Wedn.Core.Entity
{
    /// <summary>
    /// 文章归档实体拓展模型
    /// </summary>
    public class Archive
    {
        private DateTime date;
        private int count;
        /// <summary>
        /// 日期,用于拼Url
        /// </summary>
        public DateTime Date
        {
            set { date = value; }
            get { return date; }
        }
        /// <summary>
        /// 对应对象数量
        /// </summary>
        public int Count
        {
            set { count = value; }
            get { return count; }
        }
        /// <summary>
        /// Url地址
        /// </summary>
        public string Url
        {
            get
            {
                string url = string.Empty;
                //if (Utils.IsSupportUrlRewriter)
                //{
                //    //如果系统支持UrlRewriter
                string permalink = Setting.Permalink;
                if (!string.IsNullOrEmpty(permalink))
                {
                    url = Regex.Replace(permalink, "{siteurl}", Config.SiteUrl);
                    url = Regex.Replace(url, "{dire}", "archive");
                    url = Regex.Replace(url, "{alias}", this.Date.ToString("yyyyMM"));
                    url = Regex.Replace(url, "{slug}", this.Date.ToString("yyyyMM"));
                    url = Regex.Replace(url, "{id}", this.Date.ToString("yyyyMM"));
                }
                else
                {
                    url = string.Format("{0}?type=archive&y={1}&m={2}", Config.SiteUrl, this.Date.ToString("yyyy"), this.Date.ToString("MM"));
                }
                //}
                //else
                //{
                //    url = string.Format("{0}/?type=archive&date={1}", Config.SiteUrl, this.Date.ToString("yyyyMM"));
                //}
                return url;
                //return Utils.CheckPreviewThemeUrl(url); 
            }
        }

        /// <summary>
        /// a标签链接html
        /// </summary>
        public string Link
        {
            get
            {
                return string.Format("<a href=\"{0}\" >{1}</a>", this.Url, this.Date.ToString("yyyyMM"));
            }
        }

    }
}
